_init: function(name, size) {
this.actor = new St.Bin({ visible: false });
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
- this.actor.connect('notify::visible', Lang.bind(this, this._onVisibleNotify));
+ this._isLoaded = false;
+ this._isPlaying = false;
this._timeoutId = 0;
this._frame = 0;
- this._animations = St.TextureCache.get_default().load_sliced_image (global.datadir + '/theme/' + name, size, size);
+ this._animations = St.TextureCache.get_default().load_sliced_image (global.datadir + '/theme/' + name, size, size,
+ Lang.bind(this, this._animationsLoaded));
this.actor.set_child(this._animations);
},
- _disconnectTimeout: function() {
+ play: function() {
+ if (this._isLoaded && this._timeoutId == 0) {
+ if (this._frame == 0)
+ this._showFrame(0);
+
+ this._timeoutId = Mainloop.timeout_add(ANIMATED_ICON_UPDATE_TIMEOUT, Lang.bind(this, this._update));
+ }
+
+ this._isPlaying = true;
+ },
+
+ stop: function() {
if (this._timeoutId > 0) {
Mainloop.source_remove(this._timeoutId);
this._timeoutId = 0;
}
- },
- _onVisibleNotify: function() {
- if (this.actor.visible)
- this._timeoutId = Mainloop.timeout_add(ANIMATED_ICON_UPDATE_TIMEOUT, Lang.bind(this, this._update));
- else
- this._disconnectTimeout();
+ this._isPlaying = false;
},
_showFrame: function(frame) {
return true;
},
+ _animationsLoaded: function() {
+ this._isLoaded = true;
+
+ if (this._isPlaying) {
+ this._showFrame(0);
+ this._timeoutId = Mainloop.timeout_add(ANIMATED_ICON_UPDATE_TIMEOUT, Lang.bind(this, this._update));
+ }
+ },
+
_onDestroy: function() {
- this._disconnectTimeout();
+ this.stop();
}
});
transition: "easeOutQuad",
onCompleteScope: this,
onComplete: function() {
+ this._spinner.stop();
this._spinner.actor.opacity = 255;
this._spinner.actor.hide();
}
startAnimation: function() {
this._stop = false;
this.actor.reactive = false;
+ this._spinner.play();
this._spinner.actor.show();
},
gchar *path;
gint grid_width, grid_height;
ClutterActor *actor;
+ GFunc load_callback;
+ gpointer load_callback_data;
} AsyncImageData;
static void
GAsyncResult *res,
gpointer user_data)
{
+ GObject *cache = source_object;
AsyncImageData *data = (AsyncImageData *)user_data;
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
GList *list;
clutter_actor_hide (actor);
clutter_actor_add_child (data->actor, actor);
}
+
+ if (data->load_callback != NULL)
+ data->load_callback (cache, data->load_callback_data);
}
static void
* @path: Path to a filename
* @grid_width: Width in pixels
* @grid_height: Height in pixels
+ * @load_callback: (scope async) (allow-none): Function called when the image is loaded, or %NULL
+ * @user_data: Data to pass to the load callback
*
* This function reads a single image file which contains multiple images internally.
* The image file will be divided using @grid_width and @grid_height;
* Returns: (transfer none): A new #ClutterActor
*/
ClutterActor *
-st_texture_cache_load_sliced_image (StTextureCache *cache,
- const gchar *path,
- gint grid_width,
- gint grid_height)
+st_texture_cache_load_sliced_image (StTextureCache *cache,
+ const gchar *path,
+ gint grid_width,
+ gint grid_height,
+ GFunc load_callback,
+ gpointer user_data)
{
AsyncImageData *data;
GSimpleAsyncResult *result;
data->grid_height = grid_height;
data->path = g_strdup (path);
data->actor = actor;
+ data->load_callback = load_callback;
+ data->load_callback_data = user_data;
g_object_ref (G_OBJECT (actor));
result = g_simple_async_result_new (G_OBJECT (cache), on_sliced_image_loaded, data, st_texture_cache_load_sliced_image);